package org.dawning.shop.inventory.command.config;

import com.rabbitmq.client.Channel;
import org.axonframework.amqp.eventhandling.spring.SpringAMQPMessageSource;
import org.axonframework.serialization.Serializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by miou on 2017/3/25.
 */
@Configuration
public class AMQPConfiguration {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Value("${axon.amqp.exchange}")
    private String exchangeName;

    @Bean
    public Queue inventoryQueue(){
        return new Queue("inventory", false);
    }

    @Bean
    public Exchange exchange(){
        return ExchangeBuilder.topicExchange(exchangeName).durable(false).build();
    }

    @Bean
    public Binding inventoryQueueBinding() {
        return BindingBuilder.bind(inventoryQueue()).to(exchange()).with("#.inventory.#").noargs();
    }

}
